<?php
/** 注册控制器
 * @Author: 976123967@qq.com
 * @Date:   2014-09-07 20:49:53
 * @Last Modified by:   chen
 * @Last Modified time: 2014-09-08 00:04:35
 */
class RegControl extends CommonControl{
	private $model;

	public function __auto()
	{
		$this->model = K('User');
	}

	/**
	 * [index 注册控制器]
	 * @return [type] [description]
	 */
	public function index()
	{

		if(IS_POST)
		{
			if(!$this->model->create()) $this->error($this->model->error);
			$uid = $this->model->add_user();
			// 设置sesion
			session('uid',$uid);
			session('uname',Q('post.uname'));
			// 设置cookie
			setcookie(session_name(),session_id(),time()+60*60*24*7,'/');
			// 提示信息
			$this->success('注册成功',U('Index/Index/index'));
		}


		$this->display();
	}



	/**
	 * [ajaxcheck 异步验证]
	 * @return [type] [description]
	 */
	public function ajaxcheck()
	{
		if(!IS_AJAX) return false;
		$key = key($_POST);
		$content= $_POST[$key];
		if(!$this->model->check($key,$content))
		{
			$this->ajax(array('status'=>false,'msg'=>$this->model->error));
		}
		else
		{
			$this->ajax(array('status'=>true));
		}
	}
}